using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Raptor
{
  public partial class frmWebServices : Form
  {
    AppSettings thisSettings = new AppSettings();
    public frmWebServices()
    {
      InitializeComponent();
    }

    private void frmWebServices_Load(object sender, EventArgs e)
    {
      LoadWebservicesFromSettings();
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {
      if (txtWebService.Text.Length > 0)
        thisSettings.WebServices.Add(txtWebService.Text);
      else
        MessageBox.Show("Please specify a name for the web service to add");

      thisSettings.Save();
      txtWebService.Text = "";
      LoadWebservicesFromSettings();
    }

    private void LoadWebservicesFromSettings()
    {
      lstWebServices.Items.Clear();
      thisSettings = new AppSettings();
      foreach (string sItem in thisSettings.WebServices)
      {
        lstWebServices.Items.Add(sItem);
      }
    }

    private void btnRemove_Click(object sender, EventArgs e)
    {
      for (int iDX = 0; iDX < lstWebServices.Items.Count; iDX++ )
      {
        if (lstWebServices.Items[iDX].Selected)
        {
          thisSettings.WebServices.Remove(lstWebServices.Items[iDX].Text);
          thisSettings.Save();
          lstWebServices.Items[iDX].Remove();
        }
      }
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
      this.Close();
    }
  }
}